using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DamageSystem : MonoBehaviour
{
    [SerializeField] private GameObject damageVFX;

    private void OnEnable()
    {
        ActionSystem.AttachPerformer<DealDamageGA>(DealDamagePerformer);
    }
    private void OnDisable()
    {
        ActionSystem.DetachPerformer<DealDamageGA>();
    }

    private IEnumerator DealDamagePerformer(DealDamageGA dealDamageGA)
    {
        foreach (var targer in dealDamageGA.Targets)
        {
            targer.Damage(dealDamageGA.Amout);
             Instantiate(damageVFX,targer.transform.position, Quaternion.identity);
            yield return new WaitForSeconds(0.1f);
            if(targer.CurrentHealth <= 0)
            {
                if (targer is EnemyView enemyView)
                {
                    KillEnemyGA killEnemyGA = new KillEnemyGA(enemyView);
                    ActionSystem.instance.AddReaction(killEnemyGA);
                }
                else
                {

                }
            }


        }
    }

}
